package start.invoice;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 数电票生成演示类
 * 用于测试PDF生成功能
 */
public class InvoiceGeneratorDemo {
    public static void main(String[] args) {
        try {
            // 1. 创建发票数据模型
            ElectronicInvoice invoice = createSampleInvoice();

            // 2. 生成PDF
            ElectronicInvoiceGenerator generator = new ElectronicInvoiceGenerator();
            generator.generate(invoice, "数电票示例.pdf");

            System.out.println("数电票PDF生成成功！");
        } catch (IOException e) {
            System.err.println("生成数电票失败: " + e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 创建示例发票数据
     */
    private static ElectronicInvoice createSampleInvoice() {
        ElectronicInvoice invoice = new ElectronicInvoice();

        // 设置发票基本信息
        invoice.setInvoiceType("增值税专用发票（电子）");
        invoice.setInvoiceCode("XT2563700000000");
        invoice.setInvoiceNumber("25637000000000512345");
        invoice.setIssueDate("2025年02月26日 10:30:45");
        invoice.setCheckCode("370212250310012345678901234567890123456789012");

        // 设置销售方信息
        PartyInfo seller = new PartyInfo(
                "华为技术有限公司",
                "91110105MA002ABCDE",
                "北京市海淀区中关村大街1号 010-12345678",
                "中国工商银行北京分行 6222021234567890123"
        );
        invoice.setSeller(seller);

        // 设置购买方信息
        PartyInfo buyer = new PartyInfo(
                "秦始皇（个人）",
                "91110105MA002A1234",
                "陕西省西安市临潼区秦陵北路 13800138000",
                "中国建设银行西安分行 6227001234567890123"
        );
        invoice.setBuyer(buyer);

        // 设置商品明细
        List<InvoiceItem> items = new ArrayList<>();
        items.add(new InvoiceItem(
                "*塑料制品*不锈钢管-1Cr",
                "BCD-452WDPQU",
                "个",
                new BigDecimal("1"),
                new BigDecimal("7103.13"),
                new BigDecimal("7103.13"),
                "6%",
                new BigDecimal("426.19")
        ));
        items.add(new InvoiceItem(
                "*家用电器*全自动滚筒",
                "XQG100-14D1E",
                "个",
                new BigDecimal("1"),
                new BigDecimal("4730.98"),
                new BigDecimal("4730.98"),
                "9%",
                new BigDecimal("425.79")
        ));
        items.add(new InvoiceItem(
                "*厨房用具*不锈钢炒锅",
                "",
                "个",
                new BigDecimal("1"),
                new BigDecimal("5375.91"),
                new BigDecimal("5375.91"),
                "13%",
                new BigDecimal("698.87")
        ));
        invoice.setItems(items);

        // 设置汇总信息
        invoice.setSubtotalAmount("17210.02");
        invoice.setTotalTaxAmount("1550.85");
        invoice.setTotalAmount("¥18760.87");
        invoice.setTotalAmountInWords("壹万捌仟柒佰陆拾元捌角柒分");

        // 设置附加信息
        invoice.setRemarks("这是一张测试数电票，用于演示PDF生成功能。");
        invoice.setIssuer("测试开票人");
        invoice.setReviewer("李四");
        invoice.setReceiver("张三");

        return invoice;
    }
}
